import {  rule, updateRule } from '@/services/ant-design-pro/api';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import {
  PageContainer,
  ProTable,
} from '@ant-design/pro-components';
import { Badge, Button,  Input, message } from 'antd';
import React, { useRef, useState } from 'react';
import { history, Link } from '@umijs/max';


/**
 * @en-US Update node
 * @zh-CN 更新节点
 *
 * @param fields
 */
const handleUpdate = async (fields: FormValueType) => {
  const hide = message.loading('Configuring');
  try {
    await updateRule({
      name: fields.name,
      desc: fields.desc,
      key: fields.key,
    });
    hide();

    message.success('Configuration is successful');
    return true;
  } catch (error) {
    hide();
    message.error('Configuration failed, please try again!');
    return false;
  }
};

const TableList: React.FC = () => {

  /**
   * @en-US The pop-up window of the distribution update window
   * @zh-CN 分布更新窗口的弹窗
   * */


  const actionRef = useRef<ActionType>();
  const [activeKey, setActiveKey] = useState<React.Key>('tab1');
  /**
   * @en-US International configuration
   * @zh-CN 国际化配置
   * */
const arr =[
    {
      name:"市级部门行政规范性文件语料开发",
      muName:"市级部门行政规范性文件",
      tableName:"r500000tab2024102201729731_1179327_std",
      irsCode:"R500000TAB2024102201729731",
      flag:"是"
    },
     {
      name:"市级其他单位行政规范性文件语料开发",
      muName:"市级其他单位行政规范性文件",
      tableName:"r500000tab2024102201729735_1179255_std",
      irsCode:"R500000TAB2024102201729735",
      flag:"是"
    },
     {
      name:"区县政府行政规范性文件语料开发",
      muName:"区县政府行政规范性文件",
      tableName:"r500000tab2024102201729755_1179226_std",
      irsCode:"R500000TAB2024102201729755",
      flag:"是"
    },
     {
      name:"区县部门行政规范性文件语料开发",
      muName:"区县部门行政规范性文件",
      tableName:"r500000tab2024102201729756_1179209_std",
      irsCode:"R500000TAB2024102201729756",
      flag:"是"
    },
     {
      name:"区县乡镇行政规范性文件语料开发",
      muName:"区县乡镇行政规范性文件",
      tableName:"r500000tab2024102201729734_1179287_std",
      irsCode:"R500000TAB2024102201729734",
      flag:"是"
    },
     {
      name:"政策文件库数据语料开发",
      muName:"政策文件库数据",
      tableName:"jyh_policy_89680_std",
      irsCode:"R500000TAB2023101200100852",
      flag:"是"
    },
     {
      name:"政策解读数据语料开发",
      muName:"政策解读数据",
      tableName:"jyh_zcjd_90440_std",
      irsCode:"R500000TAB2023101200101053",
      flag:"是"
    }
  ]
  const [data, setData] = useState<any[]>(arr);
  const columns: ProColumns<API.RuleListItem>[] = [
    {
      title: "名称",
      dataIndex: 'name',
      search:false,
      render: (dom, entity) => {
        return (
          <a
          onClick={()=>{
            history.push( '/file/file-list')
          }}
          >
            {dom}
          </a>
        );
      },
    },
     {
      title: "目录名称",
      dataIndex: 'muName',
      search:false,
    },
    {
      title: "表名",
      dataIndex: 'tableName',
      search:false,
    },
    {
      title: "编码",
      dataIndex: 'irsCode',
      search:false,
    },
    {
      title: "是否申请",
      dataIndex: 'flag',
      search:false,
    }
  ];const renderBadge = (count: number, active = false) => {
  return (
    <Badge
      count={count}
      style={{
        marginBlockStart: -2,
        marginInlineStart: 4,
        color: active ? '#1890FF' : '#999',
        backgroundColor: active ? '#E6F7FF' : '#eee',
      }}
    />
  );
};

  return (
    <PageContainer header={{
            title: false,
           
          }}>
      <ProTable<API.RuleListItem, API.PageParams>
       
        actionRef={actionRef}
        rowKey="key"
        search={false}
        toolbar={{
    
          menu: {
            type: 'tab',
            activeKey: activeKey,
            items: [
              {
                key: 'tab1',
                label: <span>政务公开{renderBadge(7, activeKey === 'tab1')}</span>,
              },
              {
                key: 'tab2',
                label: <span>规章制度{renderBadge(2, activeKey === 'tab2')}</span>,
              },
              {
                key: 'tab3',
                label: <span>法律法规{renderBadge(1, activeKey === 'tab3')}</span>,
              },
            ],
            onChange: (key) => {
              if(key==='tab1'){
                setData(arr)
              }else if(key==='tab2'){
                setData([
                   {
                    name:"市政府规章语料开发",
                    muName:"市政府规章",
                    tableName:"r500000tab2024102201729732_1179301_std",
                    irsCode:"R500000TAB2024102201729732",
                    flag:"是"
                  },
                   {
                    name:"政策法规条目关联政务服务事项信息语料开发",
                    muName:"渝快办事项与政策法规关联关系",
                    tableName:"ykb_item_policy_rel",
                    irsCode:"",
                    flag:""
                  },
                ])
              }else{
                setData([
                    {
                    name:"地方性法规文件语料开发",
                    muName:"数据库_文件附件",
                    tableName:"",
                    irsCode:"R500000TAB2025052302696936",
                    flag:"否"
                  },
                ])
              }
              setActiveKey(key as string);
            },
          },
        
        }}
        dataSource={
          data
        }
        columns={columns}
       
      />
      
    </PageContainer>
  );
};

export default TableList;
